package com.example.everying.service.feedback.impl;/*
 * 项目名称: everything
 * 文件名: PlatformFeedBackServiceImpl
 * 作者: 张泽阳
 * 日期: 2025/5/28
 * 描述:
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.everying.mapper.feedback.PlatformFeedbackMapper;
import com.example.everying.model.vo.feedback.PlatformFeedbackVo;
import com.example.everying.model.dto.feedback.PlatformFeedbackPageDto;
import com.example.everying.model.entity.feedback.PlatformFeedBack;
import com.example.everying.service.feedback.PlatformFeedbackService;
import com.example.everying.utils.RandomUtil;
import com.example.everying.utils.Result;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class PlatformFeedBackServiceImpl extends ServiceImpl<PlatformFeedbackMapper, PlatformFeedBack> implements PlatformFeedbackService {
    @Override
    public Result<?> addFeedback(PlatformFeedBack platformFeedBack) {

        platformFeedBack.setId(RandomUtil.generateId());
        platformFeedBack.setCreateTime(LocalDateTime.now());
        int insert = baseMapper.insert(platformFeedBack);
        if (insert > 0) {
            PlatformFeedBack info = baseMapper.selectById(platformFeedBack.getId());
            return Result.ok(info);
        }
        return Result.fail("反馈失败");
    }

    @Override
    public Result<?> list(PlatformFeedbackPageDto platformFeedbackPageDto) {
        PlatformFeedBack platformFeedBack = new PlatformFeedBack();
        platformFeedBack.setContent(platformFeedbackPageDto.getContent());
        QueryWrapper<PlatformFeedBack> queryWrapper = new QueryWrapper<>();
        if (platformFeedbackPageDto.getContent() != null && platformFeedbackPageDto.getContent() != ""){
            queryWrapper.like("content", platformFeedBack.getContent());
        }
        Page<PlatformFeedBack> pageParam = new Page<>(platformFeedbackPageDto.getPage(), platformFeedbackPageDto.getLimit());
        IPage<PlatformFeedBack> pages = baseMapper.selectPage(pageParam, queryWrapper);
        if (pages != null){
            return Result.ok(pages);
        }

/*        Page<PlatformFeedbackVo> platformFeedbackVoPage = baseMapper.selectPageWithUser(pageParam, platformFeedbackPageDto);
        if (platformFeedbackVoPage != null){
            return Result.ok(platformFeedbackVoPage);
        }*/

        return Result.fail("还没有反馈信息");
    }

    @Override
    public Result<?> selectPageWithUser(Page<PlatformFeedbackVo> pageParam, PlatformFeedbackPageDto platformFeedbackPageDto) {
        return Result.ok(baseMapper.selectPageWithUser(pageParam, platformFeedbackPageDto));
    }
}

